<template>
  <!-- 添加或修改对话框 -->
  <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" width="600px"
    :close-on-click-modal="false">
    <el-form ref="dataForm" :rules="rules" :model="dataForm" status-icon label-position="left" label-width="100px"
      style="width: 80%; margin-left:50px;">
      <el-form-item label="学员课程">
        <el-select filterable  placeholder="选择课程" v-model="dataForm.associatedIndustryId" clearable
          @change="changeCompany"
          style="width: 100%;">
          <el-option v-for="(item, index) in courseData" :key="index" :label="item.categoryName" :value="item.id">
          </el-option>
        </el-select>
        <div style="color: red;">（更换课程公司本身课程和行业不会改变，只会改变当前用户的行业和课程）</div>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button size="mini" @click="dialogFormVisible = false">取消</el-button>
      <el-button size="mini" type="primary" @click="updateData">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import {
    listAssociatedIndustry,
    updateAssociatedIndustry,
    createAssociatedIndustry,
    deleteAssociatedIndustry,
    typeAssociatedIndustry
  } from '@/api/associatedIndustry'
  export default {
    data() {
      return {
        textMap: {
          update: '编辑用户',
          create: '添加用户'
        },
        rules: {
          name: [{
            required: true,
            message: '学员姓名不能为空',
            trigger: 'blur'
          }],
          phone: [{
            required: true,
            message: '学员电话不能为空',
            trigger: 'blur'
          }],
          idCard: [{
            required: true,
            message: '学员身份证不能为空',
            trigger: 'blur'
          }],
          studentsType: [{
            required: true,
            message: '学员类型不能为空',
            trigger: 'blur'
          }],
          payStatus: [{
            required: true,
            message: '缴费状态不能为空',
            trigger: 'blur'
          }],
          expireTime: [{
            required: true,
            message: '过期时间不能为空',
            trigger: 'blur'
          }],
          courseType: [{
            required: true,
            message: '课程类型不能为空',
            trigger: 'blur'
          }]
        },
        dialogStatus: '',
        dialogFormVisible: false,
        selectTF: true,
        dataForm: {},
        courseData: []
      }
    },
    methods: {
      updateData() {
        this.$refs['dataForm'].validate(valid => {
          if (valid) {
            this.dataForm.type = 'course'
            this.$emit('updateData', this.dataForm)
          }
        })
      },
      changeCompany (e) {
         this.courseData.filter(res => {
           if (res.id === e) {
             console.log(res)
             this.dataForm.categoryName = res.categoryName
             return
           }
         })
      },
      getCourseList() {
        listAssociatedIndustry({page: 1,limit: 1000000})
          .then(response => {
            this.courseData = response.data.data.items
          })
          .catch(() => {})
      },
      open(row) {
        this.dataForm = {
          ...row
        }
        this.getCourseList()
        this.dialogFormVisible = true
      },
      close() {
        this.dialogFormVisible = false
      }
    }
  }
</script>

<style scoped>

</style>
